<!-- detail header  -->
<template>
  <div>
     <router-link tag="div" to="/" class="header-abs"><div class="iconfont icon-fanhui" v-show="showAbs"></div></router-link>
     <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
        <span>景点详情</span>
        <router-link to="/">
           <div class="iconfont icon-fanhui"></div>
        </router-link>
     </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },

  components: {},

  computed: {},

  methods: {
    handleScroll () {
      var top = document.documentElement.scrollTop
      if (top > 50) {
        var opacity = top / 140
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = {
          opacity: opacity
        }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },

  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  // deactivated对全局对象的相关事件进行解绑，避免对其他页面造成影响  在页面结束时触发该方法，可清除掉滚动方法等缓存。
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}

</script>
<style lang='stylus' scoped>
@import '~styles/varibles.styl'
.header-abs
  position absolute
  left .2rem
  top .2rem
  width .8rem
  height .8rem
  border-radius .4rem
  background-color rgba(0, 0, 0, .8)
  .icon-fanhui
    color #fff
    text-align center
    width .8rem
    height .8rem
    line-height .8rem
    margin 0 auto
    font-size .4rem
.header-fixed
  z-index: 2
  position fixed
  height .86rem
  line-height .86rem
  color #fff
  top 0
  left 0
  right 0
  background $bgcolor
  text-align center
  font-size .32rem
  .icon-fanhui
      position absolute
      width .64rem
      text-align center
      font-size .3rem
      top 0
      left 0
      color #fff
</style>
